<template>
  <el-tabs type="border-card">
    <el-tab-pane>
      <span slot="label">
        <i class="el-icon-tickets"></i> 基本设置
      </span>
      
      <el-form :model="basesForm" :rules="rules" ref="basesForm" label-width="100px" class="demo-basesForm">
        <el-form-item label="网站名称" prop="webTitle">
          <el-input size="small" v-model="basesForm.webTitle" placeholder="控制在25个字、50个字节以内"></el-input>
        </el-form-item>

        <el-form-item label="关键词" prop="webKeywords">
          <el-input size="small" v-model="basesForm.webKeywords" placeholder="5个左右,8汉字以内,用英文,隔开"></el-input>
        </el-form-item>

        <el-form-item label="网站描述" prop="webDesc">
          <el-input size="small" v-model="basesForm.webDesc" placeholder="空制在80个汉字，160个字符以内"></el-input>
        </el-form-item>

        <el-form-item label="上传目录" prop="webUploadFile">
          <el-input size="small" v-model="basesForm.webUploadFile" placeholder="默认为uploadfile"></el-input>
        </el-form-item>

        <el-form-item label="版权信息" prop="webCopy">
          <el-input size="small" placeholder="© 2018 3KHOT.COM" v-model="basesForm.webCopy"></el-input>
        </el-form-item>

        <el-form-item label="备案号" prop="webIcp">
          <el-input size="small" placeholder="京ICP备00000000号" v-model="basesForm.webIcp"></el-input>
        </el-form-item>

        <el-form-item label="统计代码" prop="countCode">
          <el-input size="small" type="textarea" v-model="basesForm.countCode"></el-input>
        </el-form-item>

        <el-form-item>
          <el-button type="primary" @click="submitForm('basesForm')">{{$t('btns.save')}}</el-button>
          <el-button @click="resetForm('basesForm')">{{$t('btns.reset')}}</el-button>
        </el-form-item>
      </el-form>
    </el-tab-pane>
    <el-tab-pane>
      <span slot="label">
        <svg-icon icon-class="security" /> 安全设置
      </span>

      <el-form :model="securityForm" :rules="rules" ref="basesForm" label-width="100px" class="demo-basesForm">

        <el-form-item label="网站是否开启" prop="webIsOnLine">
          <el-switch v-model="securityForm.webIsOnLine">
          </el-switch>
        </el-form-item>

        <el-form-item label="登录失败次数" prop="webMaxLoginNum">
          <el-input-number size="small" placeholder="后台登录失败最大次数" :min="0" v-model="securityForm.webMaxLoginNum"></el-input-number>
        </el-form-item>

        <el-form-item label="IP白名单" prop="webWhiteIp">
          <el-input size="small" type="textarea" :rows="4" v-model="securityForm.webWhiteIp" placeholder="允许访问后台的IP列表"></el-input>
        </el-form-item>

        <el-form-item>
          <el-button type="primary" @click="submitForm('basesForm')">{{$t('btns.save')}}</el-button>
          <el-button @click="resetForm('basesForm')">{{$t('btns.reset')}}</el-button>
        </el-form-item>
      </el-form>
    </el-tab-pane>
    <el-tab-pane>
      <span slot="label">
        <svg-icon icon-class="email" /> 邮件设置
      </span>

      <el-form :model="emailForm" :rules="rules" ref="emailForm" label-width="120px" class="demo-emailForm">
        <el-form-item label="邮件发送模式" prop="mailSendMode">
          <el-input size="small" v-model="emailForm.mailSendMode" placeholder="邮件发送模式"></el-input>
        </el-form-item>

        <el-form-item label="SMTP服务器" prop="smtpServer">
          <el-input size="small" v-model="emailForm.smtpServer" placeholder="SMTP服务器地址"></el-input>
        </el-form-item>

        <el-form-item label="SMTP端口" prop="smtpPort">
          <el-input size="small" v-model="emailForm.smtpPort" placeholder="SMTP端口端口号"></el-input>
        </el-form-item>

        <el-form-item label="发件邮箱" prop="sendEmail">
          <el-input size="small" v-model="emailForm.sendEmail" placeholder="发件邮箱账号"></el-input>
        </el-form-item>

        <el-form-item label="邮箱密码" prop="sendEmailPwd">
          <el-input type="password" size="small" placeholder="发件邮箱密码" v-model="emailForm.sendEmailPwd"></el-input>
        </el-form-item>

        <el-form-item label="收件邮箱" prop="receivingEmail">
          <el-input size="small" placeholder="收件邮箱账号" v-model="emailForm.receivingEmail"></el-input>
        </el-form-item>

        <el-form-item>
          <el-button type="primary" @click="submitForm('emailForm')">{{$t('btns.save')}}</el-button>
          <el-button @click="resetForm('emailForm')">{{$t('btns.reset')}}</el-button>
        </el-form-item>
      </el-form>
    </el-tab-pane>
    <el-tab-pane label="其它设置">其它设置</el-tab-pane>
  </el-tabs>
</template>

<script>
  export default {
    data() {
      return {
        basesForm: {
          webTitle: '',
          webKeywords: '',
          webDesc: '',
          webUploadFile: '',
          webCopy: '',
          webIcp: '',
          countCode: ''
        },
        rules: {
          webTitle: [
            { required: true, message: '请输入网站名称', trigger: 'blur' },
            { min: 3, max: 50, message: '长度在 3 到 5 个字符', trigger: 'blur' }
          ],
          webKeywords: [
            { required: true, message: '请填写网站关键词', trigger: 'blur' },
            { min: 3, max: 20, message: '长度在 3 到 20 个字符', trigger: 'blur' }
          ],
          webDesc: [
            { required: true, message: '请填写网站描述', trigger: 'blur' },
            { min: 3, max: 160, message: '长度在 3 到 160 个字符', trigger: 'blur' }
          ],
          webUploadFile: [
            { required: true, message: '请填写网站上传位置', trigger: 'blur' }
          ],
          webCopy: [
            { required: true, message: '请填写网站版权信息', trigger: 'blur' }
          ]
        },
        securityForm: {
          webIsOnLine: false,
          webMaxLoginNum: 5,
          webWhiteIp: ''
        },
        emailForm: {
          mailSendMode: '',
          smtpServer: '',
          smtpPort: 25,
          sendEmail: '',
          sendEmailPwd: '',
          receivingEmail: ''
        }
      }
    },

    methods: {
      submitForm(formName) {
        this.$refs[formName].validate((valid) => {
          if (valid) {
            alert('submit!')
          } else {
            console.log('error submit!!')
            return false
          }
        })
      },
      resetForm(formName) {
        this.$refs[formName].resetFields()
      }
    }
  }
</script>
